package core;

import static org.junit.Assert.*;

import org.junit.Test;

public class BSTTest {

	@Test
	public void testInsert() {
		BST<Integer> bst1 = new BST<>();
		Integer[] input1 = new Integer[] { 2, 3, 1, 5, 2 };

		for (Integer i : input1)
			bst1.insert(new BST<Integer>(i));

		bst1.printInOrder(bst1);

		System.out.println();

		bst1.printPostOrder(bst1);

		System.out.println();

		bst1.printPreOrder(bst1);
	}

	@Test
	public void testSearch() {
		BST<Integer> bst1 = new BST<>();
		Integer[] input1 = new Integer[] { 2, 3, 1, 5 };
		
		for (Integer i : input1)
			bst1.insert(new BST<Integer>(i));
		
		assertEquals(null, bst1.search(4));
		assertEquals(new Integer(2), bst1.search(2).getData());
		assertEquals(new Integer(5), bst1.search(5).getData());
	}
	
	@Test
	public void testFindNextLargest() {
		BST<Integer> bst1 = new BST<>();
		Integer[] input1 = new Integer[] { 2, 3, 1, 5 };
		
		for (Integer i : input1)
			bst1.insert(new BST<Integer>(i));
		
		assertEquals(null, bst1.findNextLargest(5));
		assertEquals(new Integer(5), bst1.findNextLargest(3).getData());
		assertEquals(new Integer(3), bst1.findNextLargest(2).getData());
		assertEquals(new Integer(2), bst1.findNextLargest(1).getData());
	}

}
